-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replaced EntityMap with HashMap #9461
Replaced EntityMap with HashMap #9461
Conversation
Minimum changes required to replace the `EntityMap` structure with a type-alias of `HashMap`. `EntityMap::world_scope` has been moved replaced with `World::world_scope` to avoid creating a new trait. `HashMap` works on `&Entity` rather than `Entity` like the original `EntityMap`, which does change the public API in a minimal way.
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Hi! This is my first contribution to Bevy. I've read through the contributions document and ensured all CI tests pass locally on my machine. This pull request would Close #9357. Please let me know if there's anything else I can do to help here! |
Example |
Just ran the The check-compiles CI test that is failing also appears to be a false-positive, as it's a failure test that is still failing, just with a slightly different error message than I saw on my machine (same error code, different explanation text) |
Reverted change caused by running CI on Windows 10. Running CI on Ubuntu through WSL produces more consistent behaviour.
Confirmed |
Example |
CI is currently broken, don't worry about the bot messages. |
Glad I'm not insane! Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like how much this simplifies this code.
I'm a bit opposed to keeping around the type-alias, as I think it just obscures what's going on at this point. But I'll defer to you and the other reviewers there. The docs are nice, so if we remove it perhaps we can migrate the meaty bits to module docs for map_entities.rs
.
Removed the EntityMap type alias and moved the world_scope method onto EntityMapper.
Example |
Example |
Example |
What's the benefit of this over making the |
Because it's not used as a component, so you can't shoot yourself in the foot. This is why I suggested this approach over newtype. |
I know this is already merged, but
It's not really an argument against newtyping. newtypes is used as a pattern outside of ECS very widely, especially in the rust community. It's used to add semantic meaning. Even if the inner field is public. For example, here, you know it's specifically an map meant to be used for entity mapping, not any kind of Though having to use the API now, it feels silly to newtype specifically this. |
# Objective - Fixes bevyengine#9321 ## Solution - `EntityMap` has been replaced by a simple `HashMap<Entity, Entity>`. --- ## Changelog - `EntityMap::world_scope` has been replaced with `World::world_scope` to avoid creating a new trait. This is a public facing change to the call semantics, but has no effect on results or behaviour. - `EntityMap`, as a `HashMap`, now operates on `&Entity` rather than `Entity`. This changes many standard access functions (e.g, `.get`) in a public-facing way. ## Migration Guide - Calls to `EntityMap::world_scope` can be directly replaced with the following: `map.world_scope(&mut world)` -> `world.world_scope(&mut map)` - Calls to legacy `EntityMap` methods such as `EntityMap::get` must explicitly include de/reference symbols: `let entity = map.get(parent);` -> `let &entity = map.get(&parent);`
Objective
EntityMap
with regularHashMap
#9321Solution
EntityMap
has been replaced by a simpleHashMap<Entity, Entity>
.Changelog
EntityMap::world_scope
has been replaced withWorld::world_scope
to avoid creating a new trait. This is a public facing change to the call semantics, but has no effect on results or behaviour.EntityMap
, as aHashMap
, now operates on&Entity
rather thanEntity
. This changes many standard access functions (e.g,.get
) in a public-facing way.Migration Guide
EntityMap::world_scope
can be directly replaced with the following:map.world_scope(&mut world)
->world.world_scope(&mut map)
EntityMap
methods such asEntityMap::get
must explicitly include de/reference symbols:let entity = map.get(parent);
->let &entity = map.get(&parent);